﻿"""
Definition of views.
"""
from django.shortcuts import render
from django.http import HttpRequest,HttpResponse,HttpResponseRedirect,JsonResponse
from django.views.decorators.csrf import csrf_protect, csrf_exempt
from django.utils import timezone
from django.core import serializers
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger

from django.conf import settings
from django.core.mail import send_mass_mail
from django.core.mail import send_mail
from django.db.models import Sum
from django.db import connection

from django.template import RequestContext
from datetime import datetime
import json
import sys

#default_encoding = 'utf-8' 
# yao qing ma yhjk32
def generate_sign(params):
 try:
  keys = sorted(params.keys())
  post_str = ''
  for k,v in keys:
      k+'='+v
  for key in keys:
   post_str += key.replace('res_','') + '=>' + str(params[key]) + '&'
  post_str += 'key=' + MD5Key
  signature = MD5.new(post_str).hexdigest().upper()
  return signature
 except Exception:
  logger.error('[BSJ入金接口]生成签名失败, %s', traceback.format_exc())
  return ''

def buildParametersString(parameters,jointer):
    #keys=ksort(parameters)
    keys = sorted(params.keys())
    temp=[]
    for k,v in keys:
        temp+=k+'='+v
     return jointer.join(temp)

def ksort(d):
     return [(k,d[k]) for k in sorted(d.keys())]